<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
    <head>
        <meta charset="UTF-8">
        <title>京猫商城 login</title>
        <meta name="renderer" content="webkit|ie-comp|ie-stand">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <link rel="stylesheet" th:href="@{/css/font.css}">
        <link rel="stylesheet" th:href="@{/css/login.css}">
        <link rel="stylesheet" th:href="@{/css/xadmin.css}">
        <link rel="stylesheet" th:href="@{/lib/layui/css/layui.css}">
        <script type="text/javascript" th:src="@{/js/jquery.min.js}"></script>
        <script type="text/javascript" th:src="@{/lib/layui/layui.js}"></script>
    </head>
    <body class="login-bg">

        <div class="login layui-anim layui-anim-up">
            <div class="message">京猫商城 平台登录</div>
            <div id="darkBannerWrap"></div>

            <form method="post" class="layui-form" >
                <label for="managerName">
                    <input id="managerName" name="managerName" placeholder="用户名"  type="text" lay-verify="required" class="layui-input" >
                </label>
                <hr class="hr15">
                <label for="managerPassword">
                    <input id="managerPassword" name="managerPassword" lay-verify="required" placeholder="密码"  type="password" class="layui-input">
                </label>
                <hr class="hr15">
                <input value="登录" lay-submit lay-filter="login" style="width:100%;" type="submit">
                <hr class="hr20" >
            </form>
            <div><a href="/register_page">注册账号</a></div>
        </div>

        <script>
            $(function () {
                layui.use('form', function(){
                  const form = layui.form;
                  //监听提交
                  form.on('submit(login)', function(data){
                      console.log(data.field)
                      $.ajax({
                          url : "/login",
                          method : 'post',
                          data : data.field,
                          dataType : 'JSON',
                          success:function(res){
                              if(res.code === 0){
                                  //弹出提示，并在1秒后进行跳转
                                  layer.msg("提交成功",{icon: 1, time: 1000},function(){
                                      layer.msg(res.msg);
                                      location.href='/index_page';
                                      return false;
                                  });
                              }else{
                                  layer.msg("登录失败:" + res.msg);
                                  return false;
                              }
                          },
                          //请求的页面响应失败，则进行处理：
                          error:function (data) {
                              layer.msg(JSON.stringify(data.field),function(){
                                  location.reload();
                              });
                              return false;
                          }
                      });
                    return false;
                  });
                });
            })
        </script>
    </body>
</html>